//#include "stdafx.h"
#include <opencv2/core/core.hpp>
#include <opencv2/imgproc/imgproc_c.h>
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <cv.h>
#include <ctime>
#include <jni.h>
#include <android/log.h>

#include <cv.h>
#include <highgui.h>

#include <list>
#define ListSize 5
#define offset 7
#define angleLimit 40
#define reasonableFactor 0.3
#define sizeRatioToFrame 128

#define CANN_THRESH_low_ 190
#define CANN_THRESH_high 200

#define CANN_THRESH_low_reg 80
#define CANN_THRESH_high_reg 170

#define CANN_THRESH_low_mask_inner 100
#define CANN_THRESH_high_mask_inner 80

#define CANN_THRESH_low_mask_outer 100
#define CANN_THRESH_high_mask_outer 80

#define CANN_THRESH_low_eq 200
#define CANN_THRESH_high_eq 7500

#define VISO_TEST 0

#define Hue_range 20
#define RESIZE_IMAGE 0.5
#define FRAME_SIZE 3
#define INNER_SIZE 50
#define LOG_TAG "FaceDetection/DetectionBasedTracker"
#define LOGD(...) ((void)__android_log_print(ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__))

enum EQ
{
	NoEQ = 0,
	DoEQ = 1
};

enum Mask
{
	NoMask = 0,
	InnerMask = 1,
	OuterMask = 2
};

using namespace cv;


double euclideanDist(Point p1, Point p2);

double getAngle(Point p1, Point p2);

int FindBigestClosedContour(vector<vector<Point> > &contours, double area);

double CalcAngleOfSegment(vector<vector<Point> > &contours, int index, int maxPosition);

bool CoordinatesMakeSense(Point topLeft, Point bottomLeft, Point topRight,Point bottomRight);

vector<vector<Point> > RetrieveContours(Mat &mSrc, int optionEQ, int optionMask);

void UpdateRectangleCorners(double angle,Point ref, Point &topLeft, Point &bottomLeft, Point &topRight,Point &bottomRight,int height, int width);
void UpdateRectangleCorners(double angle,Point ref, std::list<Point> &topLeft, std::list<Point> &bottomLeft, std::list<Point> &topRight,std::list<Point> &bottomRight, int height, int width);

int* GetRectCorners(Mat &mSrc, int optionEQ,int optionMask);

int* match_points(vector<vector<Point> > contours , int maxPosition, int height, int width);

void calcMask(Mat &mSrc, Mat &result, int optionMask);

Point meanNoOutliers(std::list<Point> listOfPoints);
void DanDiag(std::list<Point> listOfPoints1,std::list<Point> listOfPoints2, Point &p1,Point &p2);
